package com.android.jay.mvp;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.android.jay.music.R;
import com.android.jay.mvc.Account;

public class MvpActivity extends AppCompatActivity implements View.OnClickListener ,IMVPView {

    private TextView mTv;
    private EditText mEt;
    private MVPPresenter mMvpPresenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mvc);
        initView();
        mMvpPresenter = new MVPPresenter(this);
    }

    private void initView() {

        mEt = findViewById(R.id.account_ed);
        mTv = findViewById(R.id.result);
        findViewById(R.id.searchbtn).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        mMvpPresenter.getData(getEnterAccount());
    }


    @Override
    public String getEnterAccount() {
        return mEt.getText().toString();
    }

    @Override
    public void showSuccessR(Account account) {
        mTv.setText(account.getUserName() + account.getLevel());
    }

    @Override
    public void showFailR() {
        mTv.setText("查询失败");
    }
}
